/*
 * @Author: lmk
 * @Date: 2021-11-24 15:02:28
 * @LastEditTime: 2021-12-16 18:29:58
 * @LastEditors: lmk
 * @Description: 
 */
// 验证是否登录 入驻 验票 设置参展信息的全局方法
import {mapGetters} from 'vuex'
export default {
	computed:{
		...mapGetters(['token','loginForm'])
	},
	methods: {
		validate({flag,content,confirmText,url,showCancel}){
			if(flag) return Promise.resolve();
			uni.showModal({
				showCancel,
				content,
				confirmText,
				title:'温馨提示',
				success:({confirm})=>confirm&&this.$u.route({url})
			})
			return Promise.reject() 
		},
		//未登录验证
		loginValidate(show=true){
			let showCancel = show == undefined?false:true
			return this.validate({flag:!!this.token,content:'登录后才能操作哦',confirmText:"去登录",url:"/pagesB/register/register",showCancel})
		},
		//验证是否入驻了平台
		planformValidate(show=true,fromPage=''){
			let showCancel = show == undefined?false:true
			const flag = this.loginForm.enterOperationStep==2;
			return this.validate({
				flag,
				content:'完善入驻信息后才能操作哦',
				confirmText:"去完善",
				url:`/pagesA/setting/setting?fromPage=${fromPage}`,
				showCancel
			})
		},
		//是否认证
		userAuthenticateValidate(show=true){
			let showCancel = show == undefined?true:false
			const flag = this.loginForm.userAuthenticate==2;
			return this.validate({flag,
			content:'完成认证后才能操作哦',
			confirmText:"去认证",
			url:`/pagesA/authPage/authPage?authType=${this.loginForm.userType=='issue' ? 2 : 3}&label=${this.loginForm.userType=='issue' ? '发行' : '门店'}认证`,showCancel})
		},
		//是否设置参展信息
		exhibitValidate(show=true){
			let showCancel = show == undefined?false:true
			const flag = this.loginForm.exhibitOperationStep==2;
			console.log(this.loginForm.exhibitOperationStep,this.$store.getters.loginForm.exhibitOperationStep)
			return this.validate({flag,content:'完善参展信息后才能操作哦',confirmText:"去完善",url:"/pagesA/larpSetting/larpSetting",showCancel})
		},
		//验票
		isBillVaildate(show=true){
			//如果已验票
			let showCancel = show == undefined?false:true
			const flag = [1,2].includes(this.loginForm.exhibitOperationStep); //已经验票或者是已经完善了信息
			return this.validate({flag,content:'请先验票后再操作',confirmText:"去验票",url:"/pagesA/validateBill/validateBill",showCancel})
		},
		//未绑定手机号码验证
		phoneValidate(){
			if(this.loginForm.phone) return Promise.resolve() 
			return Promise.reject() 
		},

		callback(){
			this.$u.route({type:'back'})
		}
	}
}
